package com.baozhun.mall.common.model.bean

import androidx.annotation.Keep
import com.baozhun.mall.common.model.enums.GoodsDescType
import com.baozhun.mall.common.model.enums.GoodsSource
import com.baozhun.mall.common.model.enums.HomeCategoryItemType
import com.blankj.utilcode.util.ScreenUtils
import com.chad.library.adapter.base.entity.MultiItemEntity
import java.io.Serializable

@Keep
class GoodsInfoBean() : Serializable, MultiItemEntity {
    var id: String = ""
    var goods_id: String = ""
    var source: String = "" //0淘宝，1天猫；2京东; 淘宝特价版;99 自营
    var source_name: String = "" //
    var goods_name: String = ""
    var goods_cover: String = ""
    var goods_images: MutableList<String> = mutableListOf()
    var brand_id: String = ""
    var brand_img: String = ""
    var brand_logo: String = ""
    var price: String = ""
    var price_desc: String = "" //需用券
    var goods_type: String = "" //0:为渠道 1:为自营
    var origin_price: String = ""
    var is_fine: String = ""
    var points_sale_price: String = "" //余额兑换价
    var share_url: String = "" //分享连接
    var points_price: String = "0" //所需余额
    var zone_id: String = "" //专区id
    var recommend_goods_list: MutableList<GoodsInfoBean> = mutableListOf()
    var sales_volume: String = "" //商品销量
    var publish_time: String = "" //发布时间
    var stock: Int = 0
    var is_zone: Int = 0 //1表示是专区，0非转区
    var zone_type: Int = 2 //1为自定义专区，2表示是品牌专区
    var zone_type_detail: Int = 2 //1为自定义专区，2表示是品牌专区

    var like_num: String? = "0" //想买的人数
    var dislike_num: String? = "0" //不想买
    var click_status: Int = 0 //点击返回状态 1:用户已经点击过想买或者不想买 2:用户点击想买或不想买成功

    var is_like: Boolean = false
    var is_get_point: Boolean = false //是否已经获得积分
    var is_show_browse: Boolean = false //是否显示浏览返标签
    var is_show_return: Boolean = false //是否显示购物返标签
    var browse_get_points: String = "" //点击获得积分
    var return_points: String? = "" //购买获得积分
    var continue_points: String? = "" //连续购买获得积分
    var continuous_buy_day_tip: String = "27天内下单" //27天内下单


    var reveal: GoodsRevealBean? = null
    var goods_no: String = ""

    var sku_id: String = ""
    var spec_info: String = ""
    var shop_name: String = ""
    var source_icon: String = ""

    var selling_points = arrayOf<String>() //卖点1
    var goods_sub_name: String = ""
    var activity_desc: String = "" //活动描述
    var exchange_desc: String = ""
    var material_url: String = "" //第三方跳转url
    var jd_skuId: String = "" //京东sdkid


    var channel_desc: String = ""
    var buy_limit: Int = 0 //限购数量
    var goods_status: Int = 1 //是否已下架 0下加 1上架
    var is_check: Boolean = false
    var updated_at: String = ""
    var goods_detail: String = ""
    var order_status_desc: String = ""
    var pay_amount: String? = null //实付金额
    var order_detail_status: Int = 0 //订单详情状
    var order_detail_status_desc: String = "" //订单详情状态描述
    var discount_amount: String? = null //订单购买时折扣价格
    var item_imgs: MutableList<String> = mutableListOf()
    var sku_list: MutableList<SkuListItem> = mutableListOf()
    var props_list: MutableList<PropsListItem> = mutableListOf()
    var coupon_list: MutableList<CouponListItem> = mutableListOf()
    var color_list: MutableList<ColorListItem> = mutableListOf()
    var ratio: Double = 1.0 //专区宽高比

    var add_amount: String = "" // 余额价格
    var sku_info: String = "" // 购物车商品规格字段
    var after_sale_no: String = ""
    var after_sale_status: Int = 0
    var canUseIntegral: Boolean = false
    var company_desc: String = ""
    var has_join_discount: MutableList<JoinDiscount> = mutableListOf()
    var total_sale_volume: String = "" // 销量
    var remained_points: String = "" //兑换价
    var platform_slogan: Boolean = false //是否是平台slogan

    //专区信息
    var detail: MutableList<SpecInfo> = mutableListOf()

    override val itemType: Int
        get() = if (platform_slogan) {
            HomeCategoryItemType.PLATFORM_SLOGAN.type
        } else if (is_zone == 1 && zone_type == 1) {
            HomeCategoryItemType.SPEC.type
        } else {
            HomeCategoryItemType.CHANNEL_GOODS.type
        }

    override fun toString(): String {
        return "productId: $id"
    }

    fun buyNumFormat(): String {
        return "x$sales_volume"
    }

    fun setIs_check(isCheck: Boolean) {
        this.is_check = isCheck
    }

    fun getNumString(): String {
        return sales_volume.toString()
    }

    fun zoneRatio(): Double {
        return if (ratio == 0.0) 1.0 else ratio
    }

    /**
     * 是否为专区
     */
    fun isZone(): Boolean {
        return is_zone == 1
    }

    /**
     * 是否无浏览返利
     */
    fun isNotBrowseGetPoints(): Boolean {
        return browse_get_points == "0.00" || browse_get_points == "0.0" || browse_get_points == "0"
    }

    /**
     * 是否为品牌专区
     */
    fun isBrandZone(): Boolean {
        return zone_type_detail == 2
    }

    /**
     * 是否显示商品销量
     */
    fun showSalesNum(): Boolean {
        return sales_volume != null && sales_volume.isNotEmpty()
    }


    /**
     *是否是淘宝商品
     */
    fun isTaoBaoGoods(): Boolean {
        return source == GoodsSource.TAO_BAO.type
    }

    /**
     *是否是淘宝商品
     */
    fun isJDGoods(): Boolean {
        return source == GoodsSource.JD.type
    }

    /**
     *是否为收藏自营商品
     */
    fun isCollectionSelfGoods(): Boolean {
        return goods_type == "1"
    }

    /**
     *是否为自营商品
     */
    fun getSourceName(): String {
        return when (source) {
            GoodsSource.TAO_BAO.type -> GoodsSource.TAO_BAO.desc
            GoodsSource.T_MALL.type -> GoodsSource.T_MALL.desc
            GoodsSource.JD.type -> GoodsSource.JD.desc
            GoodsSource.TAO_BAO_DISCOUNT.type -> GoodsSource.TAO_BAO_DISCOUNT.desc
            else -> {
                ""
            }
        }
    }

    fun getSourceInfoString(): String {
        return "$source_name | $shop_name"
    }

    fun getReturnPoints(): String {
        return if (return_points == null) "" else return_points.toString()
    }

    fun getSaleCount(): String {
        return "销量 " + (total_sale_volume.ifEmpty { "0" })
    }
}

// 已符合折扣
class JoinDiscount : Serializable {
    var id: String = ""
    var activity_title: String = ""
}


//商品爆料
class GoodsRevealBean : Serializable {
    var infos: ArrayList<GoodsRevelTextBean>? = null
    var imgs: ArrayList<GoodsRevelImgtBean>? = null
    var title: String? = "爆料内容"
}

class GoodsRevelTextBean : Serializable {
    var type: GoodsDescType = GoodsDescType.TEXT
    var title: String? = null
    var content: String = ""
}

class SpecInfo : Serializable {
    var cover: String? = ""
    var zone_id: String? = ""
    var channel_name: String? = ""
    var zone_type_detail: Int = 2 //1、独立专区，2、商品封面专区(目前只有品牌)
}

///商品描述图片
open class GoodsRevelImgtBean : Serializable {
    var url: String = ""
    var height: Int = 0
    var width: Int = 0

    private fun ratio(): Float {
        var height = if (height == 0) 1 else height
        var width = if (width == 0) 1 else width
        return width / height.toFloat()
    }

    fun getPicHeight(): Int {
        return (ScreenUtils.getScreenWidth() / ratio()).toInt()
    }
}

///sku 组合
class SkuListItem : Serializable {
    var price: String = ""
    var orginal_price: String = ""
    var points_price: String = ""
    var points_sale_price: String = ""
    var properties_name: String = ""
    var color: String = ""  //红色，白色
    var color_value: String = "" //颜色值
    var other: String = "" //其它属性
    var other_value: String = "" //其它属性值
    var stock: Int = 0
    var buy_limit: Int = 0 //限购数量
    var sold_out: Boolean = true //是否已经卖光
    var sku_id: String = ""
    var image: String = ""  //规格图片
    var color_image: String = ""  //颜色图片
}

///商品信息
class PropsListItem : Serializable {
    var name: String = ""
    var value: Array<String>? = null

    fun values(): String {
        var values = ""
        value?.forEach { it ->
            values = values.plus(it).plus(",")
        }
        return values.removeSuffix(",")
    }
}

///优惠信息
class CouponListItem : Serializable {
    var key: String = ""
    var value: String = ""

}

///商品列表颜色列表展示
class ColorListItem : Serializable {
    var img: String = ""
    var color: String = ""
    var color_img: String = ""
}



